package com.lnt.mq.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * RabbitMQ 连接工具
 */
public class RabbitUtil {

    // 创建一个连接工厂
    private static ConnectionFactory factory = new ConnectionFactory();

    static {
        // 设置连接IP
        factory.setHost("101.43.65.181");
        // 设置主机端口/连接端口
        factory.setPort(5672);
        // 设置登录信息
        factory.setUsername("developer");
        factory.setPassword("test123456");
        // 设置虚拟机
        factory.setVirtualHost("/developer");
    }

    public static Connection getConnection(){
        Connection connection = null;
        try {
            connection = factory.newConnection();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        return connection;
    }
}
